package com.gopay.solution.service.solu.impl;

import java.io.Serializable;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.gopay.common.constants.txncd.IntTxnCd;
import com.gopay.common.domain.solution.SolutionRequest;
import com.gopay.common.domain.solution.SolutionResponse;
import com.gopay.common.domain.view.config.ViewSolutionTransView;
import com.gopay.common.constants.solution.SolutionTypeConstant;

/**
 * 
 * @SsUIConfigServiceImpl.java
 * @author liujy
 * @2013-5-7 上午9:23:19  www.gopay.com.cn Inc.All rights reserved.
 */
@Service(value="ssUIConfigService")
public class SsUIConfigServiceImpl extends SolutionServiceImpl {
    
    private ThreadLocal<String> acctIdLocal = new ThreadLocal<String>();

    @Override
    public String getSolutionType() {
        return SolutionTypeConstant.TRANS_UIS;
    }

    public SolutionRequest beforeProcess(SolutionRequest request) {

        

        acctIdLocal.set(request.getAcctId());
        
        return request;
    }

    public SolutionResponse afterProcess(SolutionResponse response) {

        
        
        ViewSolutionTransView view = (ViewSolutionTransView)response.getResponse();
        
        response.setResponse(filter(view));
        
        acctIdLocal.remove();
        
        
        return response;
    }

    /**
     * UI布局方案服务：00500交易个人客户显示个人银行及企业银行，企业用户只显示企业银行
     * @param view
     * @return
     */
    private Serializable filter(ViewSolutionTransView view) {
        if(null == view){
            return view;
        }
        
        String intTxnCd = view.getIntTxnCd();
        if(!IntTxnCd._00500.value.equals(intTxnCd)){
            return view;
        }
        
        String acctId = acctIdLocal.get();
        String acctType = acctId.substring(8, 10);
        
        if(StringUtils.equals("01", acctType)){
        	// 个人
        	return view;
        }
        
        // 企业-强转默认支付客户类型为企业网银
        view.setDefalutPayUserType(acctType);
        return view;
    }
}